package com.ruoyi.project.inspection.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.inspection.domain.Vehicle;
import com.ruoyi.project.inspection.service.IVehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 车辆信息库Controller
 *
 * @author ruoyi
 * @date 2020-07-13
 */
@RestController
@RequestMapping("/inspection/vehicle")
public class VehicleController extends BaseController {
    @Autowired
    private IVehicleService vehicleService;

    /**
     * 查询车辆信息库列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:vehicle:list')")
    @GetMapping("/list")
    public TableDataInfo list(Vehicle vehicle) {
        startPage();
        List<Vehicle> list = vehicleService.selectVehicleList(vehicle);
        return getDataTable(list);
    }

    /**
     * 导出车辆信息库列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:vehicle:export')")
    @Log(title = "车辆信息库", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Vehicle vehicle) {
        List<Vehicle> list = vehicleService.selectVehicleList(vehicle);
        ExcelUtil<Vehicle> util = new ExcelUtil<Vehicle>(Vehicle.class);
        return util.exportExcel(list, "vehicle");
    }

    /**
     * 获取车辆信息库详细信息
     */
    @PreAuthorize("@ss.hasPermi('inspection:vehicle:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(vehicleService.selectVehicleById(id));
    }

    /**
     * 新增车辆信息库
     */
    @PreAuthorize("@ss.hasPermi('inspection:vehicle:add')")
    @Log(title = "车辆信息库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Vehicle vehicle) {
        return toAjax(vehicleService.insertVehicle(vehicle));
    }

    /**
     * 修改车辆信息库
     */
    @PreAuthorize("@ss.hasPermi('inspection:vehicle:edit')")
    @Log(title = "车辆信息库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Vehicle vehicle) {
        return toAjax(vehicleService.updateVehicle(vehicle));
    }

    /**
     * 删除车辆信息库
     */
    @PreAuthorize("@ss.hasPermi('inspection:vehicle:remove')")
    @Log(title = "车辆信息库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(vehicleService.deleteVehicleByIds(ids));
    }
}
